package com.peenongsaban.freelance.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.PropertyConfigurator;


public class PropertiesUtil {
	public static String pathSeparator = System.getProperty("file.separator");

	public static Properties prop = new Properties();

	public static void setProperties(Properties pro) {
		prop = pro;
	}

	public static String getConfigValue(String text) {
		String result = "";
		result = prop.getProperty(text);
		return result;
	};

	public static String getAppPath() {
		String classpath = PropertiesUtil.class.getProtectionDomain()
				.getCodeSource().getLocation().getPath(), appPath = classpath;
		if (classpath.indexOf(".jar") > -1) {
			File classPathFile = new File(classpath);
			appPath = classPathFile.getParent();
		}
		return appPath;
	}

	// TODO Configuration Path
	public static void LoadPropertiesLogFile() {
		// load configuration file log4j
		try {
			PropertyConfigurator.configure(getAppPath().concat(
					pathSeparator + "config" + pathSeparator
							+ "log.properties"));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}


	public static void LoadPropertiesConfigFile() {
		Properties pro = new Properties();
		// load configuration file properties of SMS service
		try {
			InputStream is = new FileInputStream(new File(getAppPath().concat(
					pathSeparator + "config" + pathSeparator
							+ "configuration.properties")));
			pro.load(is);
			setProperties(pro);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
